//
//  RegisterViewController.m
//  SimpleDemo
//
//  Created by tw001 on 15/8/1.
//  Copyright (c) 2015年 wave. All rights reserved.
//

#import "RegisterViewController.h"
//#import "APService.h"
#import <CoreText/CoreText.h>

#define kPhoneRegex @"^[1][3,4,5,7,8,9][\\d]{9}$"

@interface RegisterViewController ()
@property (nonatomic, strong)UITextField *filed0;
@property (nonatomic, strong)UITextField *filed1;
@property (nonatomic, strong)UITextField *filed2;
@property (nonatomic, strong)UITextField *filed3;

@property (nonatomic, strong)UIButton *selectedBtn;///阅读协议的按钮

@property (nonatomic, strong)UIScrollView *backGroundView;

@property (nonatomic, strong)UIButton *checkBtn;///获取验证码
@property (nonatomic, strong)UIButton *registerBtn;

@property (nonatomic, strong)NSTimer *timer;///获取验证码的计时器
@property (nonatomic, strong)NSTimer *statuTimer; // 按钮的计时器
@property (assign, nonatomic)BOOL isSelectCategory;

@property (nonatomic, strong)UIButton *leftBtn;

@property (nonatomic, strong)UIView *readView;///协议View

@property (nonatomic, assign)NSInteger length;

@property (assign,nonatomic)int userNameType; //用户名输入完成后判断是手机号还是邮箱 0为手机号 1为邮箱
@property (assign,nonatomic)BOOL status;


@end

@implementation RegisterViewController

- (void)dealloc
{
    NSLog(@"注册界面释放");
    [_timer invalidate];
    _timer = nil;
    [_statuTimer invalidate];
    _statuTimer = nil;
    a = 60;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    if (!_timer) {
        _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeNum:) userInfo:nil repeats:YES];
        [_timer setFireDate:[NSDate distantFuture]];
    }
    
    if (!_statuTimer) {
        _statuTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(statusChange:) userInfo:nil repeats:YES];
    }

    _isSelectCategory = NO;
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
    if (_isSelectCategory == NO) {
        [_timer invalidate];
        _timer = nil;
        [_statuTimer invalidate];
        _statuTimer = nil;
    }
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _isSelectCategory = NO;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"注册";
    
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _leftBtn.frame = CGRectMake(5, 0, 8.5,17);
    [_leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [_leftBtn addTarget:self action:@selector(dismissToRoot) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_leftBtn];
    
    _backGroundView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    _backGroundView.showsHorizontalScrollIndicator = NO;
    _backGroundView.showsVerticalScrollIndicator = NO;
    if ([[HLManager sharedManager] isOver5S] == NO) {
        [_backGroundView setContentSize:CGSizeMake(_backGroundView.frame.size.width, _backGroundView.frame.size.height + 216 - 64)];
    }
    [self.view addSubview:_backGroundView];
    
    CGSize size = CGSizeMake(self.view.frame.size.width*3.5/5.0,26);
   _filed0 = [self builtEveryNoticeWithTitle:@"用户名：" andPlaceHolder:@"  请输入手机号/邮箱" andY:86 andSize:size];
    _filed0.keyboardType = UIKeyboardTypeEmailAddress;
    _filed0.inputAccessoryView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.35)];
    _filed0.inputAccessoryView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
    [_filed0 becomeFirstResponder];
    
    _filed1 = [self builtEveryNoticeWithTitle:@"密码：" andPlaceHolder:@"  请设置6-12位密码" andY:86+38 andSize:size];
    _filed1.secureTextEntry = YES;
    _filed2 = [self builtEveryNoticeWithTitle:@"确认密码：" andPlaceHolder:@"  请再输入一遍" andY:86+38+38 andSize:size];
    _filed2.secureTextEntry = YES; 
    _filed2.delegate = self;
    
    CGSize size0 = CGSizeMake(size.width/2.0-2,26);
    _filed3 = [self builtEveryNoticeWithTitle:@"验证码：" andPlaceHolder:@"  请输入验证码" andY:86+38*3 andSize:size0];
    _filed3.keyboardType = UIKeyboardTypeNumberPad;
    _filed3.inputAccessoryView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.35)];
    _filed3.inputAccessoryView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
    _filed3.delegate = self;
    
    _checkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _checkBtn.frame = CGRectMake(_filed3.frame.origin.x+_filed3.frame.size.width+4, _filed3.frame.origin.y, size0.width - 4,26);
    _checkBtn.layer.cornerRadius = 3;
    _checkBtn.clipsToBounds=YES;
    _checkBtn.layer.borderColor=COLOR(255, 162, 33, 1).CGColor;
    _checkBtn.layer.borderWidth=1;
    NSMutableAttributedString *checkString=[[NSMutableAttributedString alloc]initWithString:@"获取验证码"];
    [checkString addAttribute:NSForegroundColorAttributeName value:COLOR(255, 162, 33, 1) range:NSMakeRange(0,checkString.length)];
    
    [_checkBtn setAttributedTitle:checkString forState:UIControlStateNormal];
    _checkBtn.titleLabel.font = [UIFont systemFontOfSize:13];
   
    [_checkBtn addTarget:self action:@selector(checkBtnForPWD:) forControlEvents:UIControlEventTouchUpInside];
    [_backGroundView addSubview:_checkBtn];
    
    _selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _selectedBtn.frame = CGRectMake(_filed3.frame.origin.x-45, _filed3.frame.origin.y + _filed3.frame.size.height +20, 15, 15);
    [_selectedBtn addTarget:self action:@selector(selectedbtnSelected:) forControlEvents:UIControlEventTouchUpInside];
    _selectedBtn.selected = YES;
    [_selectedBtn setImage:[UIImage imageNamed:@"0811_noread"] forState:UIControlStateNormal];
    [_selectedBtn setImage:[UIImage imageNamed:@"0811_hasread"] forState:UIControlStateSelected];
    [_backGroundView addSubview:_selectedBtn];
    
    NSString *title0 = @"我已阅读并同意农产品集购网的";
    CGRect rect = [title0 boundingRectWithSize:CGSizeMake(200, 18) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(_selectedBtn.frame.origin.x+_selectedBtn.frame.size.width+4, _selectedBtn.frame.origin.y, rect.size.width, 18)];
    label.text = title0;
    label.font = [UIFont systemFontOfSize:13];
    [_backGroundView addSubview:label];
    
    UIButton *readBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    readBtn.frame = CGRectMake(label.frame.size.width+label.frame.origin.x, label.frame.origin.y, 95, 15);
    readBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [readBtn setTitle:@"《用户协议》" forState:UIControlStateNormal];
    [readBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [readBtn setExclusiveTouch:YES];
    [readBtn addTarget:self action:@selector(readBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_backGroundView addSubview:readBtn];
    
    HLManager *lbxManager=[HLManager sharedManager];
    
    if ([lbxManager isOver5S] == NO) {
        _selectedBtn.frame = CGRectMake(_filed3.frame.origin.x-60, _filed3.frame.origin.y + _filed3.frame.size.height +20, 15, 15);
        label.frame = CGRectMake(_selectedBtn.frame.origin.x+_selectedBtn.frame.size.width+4, _selectedBtn.frame.origin.y, rect.size.width, 15);
        readBtn.frame = CGRectMake(label.frame.size.width+label.frame.origin.x, label.frame.origin.y, 95, 15);
    }
    
    _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _registerBtn.frame = CGRectMake(kDeviceWidth/2-75, _selectedBtn.frame.origin.y+15+44,150,29);
//    _registerBtn.backgroundColor = [UIColor colorWithRed:21/255.0 green:146/255.0 blue:114/255.0 alpha:1];
    _registerBtn.layer.borderColor=COLOR(36, 148, 88, 1).CGColor;
    _registerBtn.layer.borderWidth=1;
    [_registerBtn setTitleColor:COLOR(36, 148, 88, 1) forState:UIControlStateNormal];
    [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    _registerBtn.layer.cornerRadius = 5;
    _registerBtn.clipsToBounds=YES;
 
    [_registerBtn addTarget:self action:@selector(registerBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    _registerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_backGroundView addSubview:_registerBtn];

}

- (void)readBtnClicked:(UIButton *)sender
{
    _isSelectCategory = YES;
    AgreementViewController *agreementVC = [[AgreementViewController alloc]init];
    [self.navigationController pushViewController:agreementVC animated:NO];
}

- (void)endEdit:(UITapGestureRecognizer *)tap
{
    [self.view endEditing:YES];
    [_backGroundView setContentOffset:CGPointZero animated:YES];
}

- (UITextField *)builtEveryNoticeWithTitle:(NSString *)title andPlaceHolder:(NSString *)placeHolder andY:(CGFloat)y andSize:(CGSize )size
{
    NSString *title0 = [NSString stringWithFormat:@"*%@",title];
    NSMutableAttributedString *attributedString0 = [[NSMutableAttributedString alloc]initWithString:title0];
    NSRange redRange = NSMakeRange(0, 1);
    [attributedString0 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, y-5, self.view.frame.size.width*1/4.0, 35)];
    label.textAlignment = NSTextAlignmentRight;
    label.attributedText = attributedString0;
    label.font = [UIFont systemFontOfSize:17];
    [_backGroundView addSubview:label];
    
    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(label.frame.size.width+label.frame.origin.x +3, y, size.width, size.height)];
    field.backgroundColor = [UIColor whiteColor];
    field.borderStyle = UITextBorderStyleNone;
    field.layer.cornerRadius = 2;
    field.layer.borderWidth = 0.5;
    field.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [_backGroundView addSubview:field];
    
    UITextField *textFiled = [[UITextField alloc]initWithFrame:CGRectMake(label.frame.size.width+label.frame.origin.x +3+5, y, size.width, size.height)];
    textFiled.borderStyle = UITextBorderStyleNone;
    textFiled.layer.borderWidth = 0;
    textFiled.placeholder = placeHolder;
    [_backGroundView addSubview:textFiled];
    HLManager *lbxManager=[HLManager sharedManager];
    if ([lbxManager isOver5S] == NO) {
        label.font = [UIFont systemFontOfSize:15];
        label.frame = CGRectMake(0, y, self.view.frame.size.width*1.1/4.0, 35);
        textFiled.font = [UIFont systemFontOfSize:15];
    }
    return textFiled;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//    RequestManger *request = [RequestManger sharerequestManger];
    HLManager *lbxmanager=[HLManager sharedManager];
    if ([lbxmanager isOver5S] == NO) {
        if (textField == _filed2) {
            [_backGroundView setContentOffset:CGPointMake(0, 100) animated:YES];
        }
        if (textField == _filed3) {
            [_backGroundView setContentOffset:CGPointMake(0, 150) animated:YES];
        }
        if (textField == _filed0 || textField == _filed1) {
            [_backGroundView setContentOffset:CGPointZero animated:YES];
        }
    }
    return YES;
}

/// 阅读协议按钮
- (void)selectedbtnSelected:(UIButton *)sender
{
    sender.selected = !sender.selected;
}

/// 获取验证码的方法
- (void)checkBtnForPWD:(UIButton *)sender
{
  
    [self checkUserNameIsUsed];
    
}
static int a=60;
- (void)setResetTimer
{
    [_checkBtn setTitle:@"获取动态码" forState:UIControlStateNormal];
    [_checkBtn setEnabled:YES];
//    [_checkBtn setBackgroundColor:kOrangeColor];
    [_timer setFireDate:[NSDate distantFuture]];
    a = 60;
}

//检测手机号是否符合规范，用于注册时鉴定手机号

- (BOOL)checkPhoneNum:(NSString *)phone
{
    NSString *regex2 = kPhoneRegex;
    NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex2];
    BOOL isMatch2 = [pred2 evaluateWithObject:phone];
    return isMatch2;
}

///提交注册的方法
- (void)registerBtnClicked:(UIButton *)sender
{
      NSLog(@"***");
    [self loginSuccessAndBackWithDictionary:nil];
    
    
//    HLManager *lbx=[HLManager sharedManager];
//    NSString *phone = [lbx makeDownWithTextField:_filed0];
//    
//    [self.view endEditing:YES];
//    [_backGroundView setContentOffset:CGPointZero animated:YES];
//    
//    if ([lbx checkIsHasNetworkFunction]) {
//        if (_selectedBtn.selected) {
//            ///提交注册
//            NSLog(@"提交注册");
//            if ([self checkPhoneNum:phone]^[lbx checkEmailAddress:phone]) {//手机号码无误
//                if (_filed1.text.length >= 6&&_filed1.text.length <= 12) {//密码长度符合要求
//                    if ([_filed2.text isEqualToString:_filed1.text]) {//再次输入密码正确
//                        if (_filed3.text.length == 6) {//验证码输入
//
//                            [_statuTimer setFireDate:[NSDate distantFuture]];
//                            
//                            AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//                            manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//                            manager.requestSerializer.timeoutInterval = kTimeoutInterval;
//                            manager.securityPolicy = [lbx getHttpsSetting];
//
////                            [_registerBtn setBackgroundColor:kGrayColor];
//                            [_registerBtn setEnabled:NO];
//                            
//                            // 填写表单
//                            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
//                            [dict setObject:phone forKey:@"memberName"];
//                            [dict setObject:_filed1.text forKey:@"password"];
//                            [dict setObject:_filed3.text forKey:@"verifyCode"];
//                            [dict setValue:@(_userNameType) forKey:@"registType"];
//                            NSString *urlStr = [NSString stringWithFormat:@"%@/front/member/registMember.do",kServerNetwork];
//                            
//                            [manager POST:urlStr parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//                            } success:^(AFHTTPRequestOperation *operation, id responseObject) {
//                                if (responseObject) {
//                                    
//                                    NSError *error = nil;
//                                    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];
//                                    
//                                    if ([[dict objectForKey:@"status"] intValue] == 1) {
//                                        [self setResetTimer];
//                                        [self loginSuccessAndBackWithDictionary:dict];
//                                    } else {
//                                        NSString *str = [dict objectForKey:@"detail"];
//                                        if ([str isEqualToString:@"短信验证码为空"]) {
//                                            str = @"未获取短信验证码";
//                                        }
//                                        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//                                        [av show];
//                                        [_statuTimer setFireDate:[NSDate distantPast]];
//                                    }
//                                }
//                                [_registerBtn setEnabled:YES];
//                            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//                                NSLog(@"error = %@",error.description);
//                                [lbx showHudText:@"注册失败, 请稍后再试" detailsText:nil afterDelay:1];
//                                [_registerBtn setEnabled:YES];
//                                [_statuTimer setFireDate:[NSDate distantPast]];
//                            }];
//                            
//                        }else{
////                            [_filed3 becomeFirstResponder];
//                            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"验证码输入有误，请检查后重试" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//                            [alertView show];
//                        }
//                    }else{
////                        [_filed1 becomeFirstResponder];
//                        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"两次密码输入不同，请检查后重试" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//                        [alertView show];
//                    }
//                }else{
////                    [_filed1 becomeFirstResponder];
//                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"密码长度不符合要求，请检查后重试" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//                    [alertView show];
//                }
//            }else{
////                [_filed0 becomeFirstResponder];
//                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手机号码输入有误，请检查后重试" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//                [alertView show];
//            }
//
//        } else {
//            
//            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在\"我已阅读并同意农产品集购网的<<农产品协议>>\"打对勾" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
//            [alertView show];
//        }
//    } else {
//        [lbx showHudText:@"网络连接失败" detailsText:nil afterDelay:1];
//    }
}

///计时器计算获取验证码的时间
- (void)changeNum:(NSTimer*)timer
{
    if (a > 0) {
        NSString *aString=[NSString stringWithFormat:@"%d",a];
        NSMutableAttributedString *Mutablestring=[[NSMutableAttributedString alloc]initWithString:aString];
        [Mutablestring addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0,aString.length)];
        
        [_checkBtn setAttributedTitle:Mutablestring forState:UIControlStateNormal];
        a--;
    }else{
        NSMutableAttributedString *astring=[[NSMutableAttributedString alloc]initWithString:@"获取动态码"];
        [astring addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0,5)];
        [_checkBtn setAttributedTitle:astring forState:UIControlStateNormal];
        [_checkBtn setEnabled:YES];
        [_timer setFireDate:[NSDate distantFuture]];
        a = 60;
    }

}

///注册成功默认登录也成功
- (void)loginSuccessAndBackWithDictionary:(NSDictionary *)dic
{
    [self.navigationController popViewControllerAnimated:YES];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"hiddenSelf" object:nil];
    [[NSNotificationCenter defaultCenter]postNotificationName:kGetSelfInfo object:nil];
}


#pragma mark - StatusChangeTimer
- (void)statusChange:(NSTimer *)timer
{
    if (_filed0.text.length && _filed1.text.length && _filed2.text.length && _filed3.text.length >= 6 && _selectedBtn.selected) {
//        [_registerBtn setBackgroundColor:kGreenColor];
        [_registerBtn setEnabled:YES];
    } else {
//        [_registerBtn setBackgroundColor:kGrayColor];
        [_registerBtn setEnabled:NO];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dismissToRoot
{
    [self.navigationController popViewControllerAnimated:NO];
}

-(void)checkUserNameIsUsed
{
    HLManager *hl=[HLManager sharedManager];
    NSString *userName = [hl makeDownWithTextField:_filed0];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = kTimeoutInterval;
    manager.securityPolicy = [hl getHttpsSetting];
    
    // 填写表单
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setObject:userName forKey:@"memberName"];
    NSString *urlStr = [NSString stringWithFormat:@"%@/front/member/isExistMemberName.do",kServerNetwork];
    
    [manager POST:urlStr parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
    }
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
              
              NSLog(@"responseObject = %@",responseObject);
              
              NSError *error = nil;
              NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];
              NSLog(@"dict++--,,%@",dict);
              
              if ([[dict objectForKey:@"status"] intValue]==1) {
                  
                  _status=[[dict objectForKey:@"data"]intValue];
                  [self getYanZhengMa:userName];
              }
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              NSLog(@"error = %@",error.description);
          }];
}


-(void)getYanZhengMa:(NSString *)userName
{
    HLManager *hl=[HLManager sharedManager];
    if (_status!=1) {
        if ([userName containsString:@"@"]) {
            
            if ([hl checkEmailAddress:userName]) {
                _userNameType=1;
            }
            else
            {
                [hl showHudText:@"邮箱格式不正确" detailsText:nil afterDelay:1];
                return;
            }
        }
        else
        {
            if ([hl checkPhoneNum:userName]) {
                _userNameType=0;
            }
            else
            {
                [hl showHudText:@"手机号格式不正确" detailsText:nil afterDelay:1];
                return;
            }
        }
    }
    else
    {
        
        [hl showHudText:@"用户名已存在" detailsText:nil afterDelay:1];
        return;
    }
    
    if ([hl checkIsHasNetworkFunction]) {
        
        [_timer setFireDate:[NSDate distantPast]];
        [_checkBtn setEnabled:NO];
        
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        manager.requestSerializer.timeoutInterval = kTimeoutInterval;
        manager.securityPolicy = [hl getHttpsSetting];
        
        // 填写表单
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        
        
        NSString *urlStr;
        if (_userNameType==0) {
            urlStr = [NSString stringWithFormat:@"%@/front/member/getMobileVerifyCode.do",kServerNetwork];
            [dict setObject:userName forKey:@"mobile"];
        }
        else
        {
            urlStr = [NSString stringWithFormat:@"%@/front/member/getEmailVerifyCode.do",kServerNetwork];
            [dict setObject:userName forKey:@"email"];
        }
        
        [manager POST:urlStr parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            
        } success:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            NSError *error = nil;
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];
            if ([[dict objectForKey:@"status"] intValue] != 1) {
                [self setResetTimer];
            }
            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"提示" message:[dict objectForKey:@"detail"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [av show];
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"error = %@",error.description);
            [self setResetTimer];
        }];
        
    }else{
        [hl showHudText:@"网络连接失败" detailsText:nil afterDelay:1];
    }

}


@end
